- Write a complete C++ program that does the following:
- Reads 5 numbers from a user and stores each number in a takes a 1D array
- Moves each entry in an array one place forward (to the right) and moves the right-most entry back to the beginning.
- Prints the resulting array to the monitor with each entry separated by a space.
Sample run of program>
Enter five numbers: 1 2 3 4 5
Shifted array: 5 1 2 3 4
- Write a complete C++ program that has two integer arrays called input and output that each have capacity 10. Fill the input array with random numbers between 1 and 9. Print the contents of the array to the monitor. The program then reads each entry of the input array and sets the entry of the output array for that same index to 3 if the integer at that index is divisible by 3, and 0 if the integer at that index is not divisible by 3.
Sample run of program:
Input array values:
6 4 6 3 3 4 8 7 4 8
Output array values:
3 0 3 3 3 0 0 0 0 0
- Write a complete C++ program that does the following:
- Fills an integer array of size 15 with random numbers between -10 and 10.
- Prints the array elements, each separated by a space
- Calculates the percentage of negative entries
- Prints the count of negative entries to the monitor.
Sample run of program:
8 0 -10 9 4 -7 -8 5 9 -6 -7 10 -5 -9 9
Percentage of negative entries: 46.6667%
- Write a complete C++ program that does the following:
- Asks the user for a positive integer n that has five digits.
- The program stores each digit of n in an integer array.
- The program prints all the odd digits of n from left to right.
- The program then prints all even digits of n from right to left.
Sample run of program:
Please enter a five-digit integer: 74829
The odd digits from left to right are 7 9
The even digits from right to left are 2 8 4
- Write a complete C++ program that does the following:
- Declares a 2 x 5 array of ints called x and initializes it to a set of values.
- The main function passes array x to a function called maxRow that returns the index of the row in the array that has the maximum number of positive entries.
- If there is more than one row that gives the maximum, you can return any of these possibilities.
- The main function then prints the index of the row containing the largest count of positive entries.
The following main function uses maxRow:
int main(){
int x[2][5] = { {-1, -2, 1, -3, 5}, {-5, -6, -4, -7, -8} };
cout << maxRow(x, 2, 5); // prints 0
// because row 0 has two positive entries and row 1 has none
return 0;
}